package com.hhh.Service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhh.Mapper.SetmealDishMapper;
import com.hhh.Pojo.SetmealDish;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealDishSerivce implements com.hhh.Service.SetmealDishSerivce {

    @Autowired
    SetmealDishMapper setmealDishMapper;

    //    添加套餐关联菜品
    @Override
    public Integer Insert(SetmealDish setmealDish) {
        return setmealDishMapper.insert(setmealDish);
    }

    //    删除套餐关联菜品
    @Override
    public Integer Delete(SetmealDish setmealDish) {
        QueryWrapper<SetmealDish> wrapper = new QueryWrapper<>();
        wrapper.eq("setmeal_id", setmealDish.getSetmealId());
        return setmealDishMapper.delete(wrapper);
    }

    //    根据套餐id查询关联菜品
    @Override
    public List<SetmealDish> SelectBySetmealId(long SetmealId) {
        QueryWrapper<SetmealDish> wrapper = new QueryWrapper<>();
        wrapper.eq("setmeal_id", SetmealId);
        return setmealDishMapper.selectList(wrapper);
    }

    //    更新套餐关联菜品
    @Override
    public Integer Update(List<SetmealDish> setmealDishList) {
        int num = 0;
        for (SetmealDish setmealDish : setmealDishList) {
            num += setmealDishMapper.updateById(setmealDish);
        }
        return num;
    }
}
